﻿using System;
using UFSoft.UBF.Cust.ClassView.MVC.Debug;
using UFSoft.UBF.Util.Log;
using UFIDA.U9.Cust.Pub.WebSocketSharp;
using UFIDA.U9.Cust.Pub.WebSocketSharp.Server;

namespace UFSoft.UBF.Cust.ClassView.MVC.WebSocket
{
    /// <summary>
    ///     事务调试
    /// </summary>
    public class TransactionDebugBehavior : WebSocketBehavior
    {
        private static readonly ILogger Logger = LoggerManager.GetLogger(typeof(TransactionDebugBehavior));
        public static string Path = "/ClassView/TransactionDebug";

        public string ProxyType
        {
            get { return QueryString["proxyType"]; }
        }

        protected override void OnOpen()
        {
            base.OnOpen();
            if (string.IsNullOrEmpty(ProxyType))
            {
                TransactionDebug.Instance.Setup(0);
            }
            else
            {
                TransactionDebug.Instance.Setup(1, ProxyType);
            }
        }

        protected override void OnClose(CloseEventArgs e)
        {
            base.OnClose(e);
            if (string.IsNullOrEmpty(ProxyType))
            {
                TransactionDebug.Instance.Stop(0);
            }
            else
            {
                TransactionDebug.Instance.Stop(1, ProxyType);
            }
        }

        protected override void OnError(ErrorEventArgs e)
        {
            Logger.Error("TransactionDebugBehavior error" + e.Message);
        }
    }
}